import React, { Component } from 'react'
import './count.css'

export default class Count extends Component {
  state = {
    carName: '梅赛德斯奔驰',
  }

  increament = () => {
    const { value } = this.selectRef
    this.props.increment(value*1)
  }

  decrement = () => {
    const { value } = this.selectRef
    this.props.decrement(value*1)
  }

  increamentIfOdd = () => {
    const { value } = this.selectRef
    if (this.props.count % 2) {
      this.props.increment(value*1)
    }
  }

  increamentAsync = () => {
    const { value } = this.selectRef
    this.props.incrementAsync(1000, value*1)
  }

  render() {
    console.log(this.props)
    // const { store } = this.props
    return (
      <div className="count">
        <h1>当前求和为: {this.props.count}</h1>
        <select ref={c => (this.selectRef = c)}>
          <option value="1">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
        </select>
        <div className="btns">
          <button onClick={this.increament}>+</button>
          <button onClick={this.decrement}>-</button>
          <button onClick={this.increamentIfOdd}>当前求和为奇数再加</button>
          <button onClick={this.increamentAsync}>异步加</button>
        </div>
      </div>
    )
  }
}
